from models import Page
from django.http import Http404
from django.views.generic.simple import direct_to_template
from pagemagic.core import get_page_from_request

def handle_page(request):
    try:
        page = get_page_from_request(request)
    except Page.DoesNotExist:
        raise Http404('Pagemagic cannot find page by path `%s`' % request.path)

#    if not page.content.template:
#        raise Http404('Page`%s` without template' % request.path)

    return direct_to_template(request, page.content.template)

